package com.hxzon.aixzsecretary.net;

import java.io.BufferedOutputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Date;

public class ChatClient extends Thread {
	private String IP;
	private int port = 4001;
	private String myname;
	private String myIP;
	private String chatContent;

	public ChatClient(String IP, String myname, String myIP, String chatContent) {
		this.IP = IP;
		this.myname = myname;
		this.myIP = myIP;
		this.chatContent = chatContent;
		// SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		// nowtime=df.format(new Date());
	}// end AizqChatClient

	public void run() {
		Socket socket;
		try {
			socket = new Socket(IP, port);
			// DataOutputStream dos=new DataOutputStream(
			// new BufferedOutputStream(socket.getOutputStream()));
			ObjectOutputStream dos = new ObjectOutputStream(
					new BufferedOutputStream(socket.getOutputStream()));
			// user data
			dos.writeUTF(myname);
			dos.flush();
			dos.writeUTF(myIP);
			dos.flush();
			dos.writeObject(new Date());// send time
			dos.flush();
			// chat data
			dos.writeUTF(chatContent);
			dos.flush();
			// close
			dos.close();
		} catch (Exception e) {
		}
	}// end run
}
